package com.yunhe.day322.service.impl;

import com.github.pagehelper.PageHelper;
import com.yunhe.day322.dao.OrderDao;
import com.yunhe.day322.dao.ProductDao;
import com.yunhe.day322.domain.Product;
import com.yunhe.day322.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductDao productDao;
    @Autowired
    private OrderDao orderDao;
    /**
     * 添加产品
     * @param product
     */
    @Override
    public void addProduct(Product product) {
//调用持久层
        productDao.addProduct(product);
    }

    @Override
    public List<Product> findAllProduct(int page, int size) {
        PageHelper.startPage(page,size);
        //调用持久层
        List<Product> list = productDao.findAllProduct();
        return list;
    }

    @Override
    public Product findById(String pid) {
        return productDao.findById(pid);
    }

    @Override
    public void edit(Product product) {
              productDao.edit(product);
    }

    @Override
    public void deleteById(String id) {
          productDao.deleteById(id);
          orderDao.updateById(id);
    }

    @Override
    public List<Product> findAll() {

        return productDao.findAll();
    }
}
